package com.songshuai.webapi.jobapi.dto.base;

import com.songshuai.webapi.jobapi.common.enumerations.ResultStatus;
import lombok.Data;

@Data
public class QueryResponse<T> {

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 返回信息描述
     */
    private String message;

    /**
     * 页数（分页查询时使用）
     */
    private long count;

    public QueryResponse() {
        code = ResultStatus.SUCCESS.getErrorCode();
        message = ResultStatus.SUCCESS.getErrorMsg();
    }

    public QueryResponse(ResultStatus resultStatus) {
        code = resultStatus.getErrorCode();
        message = resultStatus.getErrorMsg();
    }

    public static <T> QueryResponse setResData(T data) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        return res;
    }

    public static <T> QueryResponse setResData(T data,long count) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        res.setCount(count);
        return res;
    }

    public static <T> QueryResponse setResData(T data, ResultStatus resultStatus) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        res.setCode(resultStatus.getErrorCode());
        res.setMessage(resultStatus.getErrorMsg());
        return res;
    }

    public static <T> QueryResponse setResData(T data, ResultStatus resultStatus, String msg) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        res.setCode(resultStatus.getErrorCode());
        res.setMessage(msg);
        return res;
    }

    public static <T> QueryResponse setResData(T data, Integer errCode, String msg) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        res.setCode(errCode);
        res.setMessage(msg);
        return res;
    }


}
